import React, { PureComponent } from 'react';
import { Icon, Checkbox, Input, Button, Form } from 'antd';
import { connect } from 'dva';
import "../../../Common.less"
import "./login.less"
class LoginForm extends PureComponent {
    constructor(props) {
        super(props);
        this.state = {
        }
        this.handleSubmit = this.handleSubmit.bind(this)
    }
     handleSubmit(e) {
        e.preventDefault();
    
        this.props.form.validateFields(async (err, values) => {
            if (!err) {
                await this.props.getDictList()
                sessionStorage.setItem("isLogin",true)
                if(sessionStorage.getItem("hisPre")){
                    this.props.history.push(sessionStorage.getItem("hisPre"))
                }else{
                     this.props.history.go(-1)
                }
               
            }
        });
    };
    render() {
        const { getFieldDecorator } = this.props.form;
        return (
            <div className="loginForm" style={{backgroundImage:`url(${process.env.NODE_ENV=="production"?"/srd":""}/static/images/bg.jpg)`,backgroundRepeat:"no-repeat"}}>
                
                <Form style={{ width: "500px",flexDirection:"column" }} onSubmit={this.handleSubmit} className="login-form">
                <h2>智能设计平台</h2>
                <h2>用户登录</h2>
                    <Form.Item>
                        {getFieldDecorator('username', {
                            rules: [{ required: true, message: '请输入用户名!' }],
                        })(
                            <Input
                                prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />}
                                placeholder="请输入用户名"
                            />,
                        )}
                    </Form.Item>
                    <Form.Item>
                        {getFieldDecorator('password', {
                            rules: [{ required: true, message: '请输入密码!' }],
                        })(
                            <Input
                                prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />}
                                type="password"
                                placeholder="请输入密码"
                            />,
                        )}
                    </Form.Item>
                    <Form.Item>
                        {getFieldDecorator('remember', {
                            valuePropName: 'checked',
                            initialValue: true,
                        })(<Checkbox>记住用户</Checkbox>)}

                        <Button type="primary" htmlType="submit" className="login-form-button">登录</Button>
                    </Form.Item>
                </Form>
                <div className="beianhao">
                    <img src="https://img.alicdn.com/tfs/TB1..50QpXXXXX7XpXXXXXXXXXX-40-40.png" alt=""/>
                    <a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo">鄂ICP备17001168号</a>
                </div>
            </div>
        )
    }
}
export default connect(
    ({

    }) => {
        return {};
    },
    dispatch => ({
        getDictList: (params) => dispatch({
            type: 'dict/getDictList',
            payload: params
        }),
    })
)(Form.create('LoginForm', {

})(LoginForm));